#!/bin/sh -e

# Adds optional libedit support
cpt-list -q libedit &&
    libedit="--with-libedit" LIBS="$(pkgconf --static --libs libedit)"

export LIBS
export LDFLAGS="$LDFLAGS -static"

./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --datadir=/usr/share/openssh \
    --sysconfdir=/etc/ssh \
    --without-selinux \
    --with-privsep-user=nobody \
    --with-mantype=doc \
    --without-rpath \
    --disable-strip \
    --with-pid-dir=/run \
    --disable-wtmp \
    --disable-utmp \
    "$libedit"

make
make DESTDIR="$1" install

clinst -m 755 contrib/ssh-copy-id "$1/usr/bin/ssh-copy-id"
clinst -m 644 contrib/ssh-copy-id.1 "$1/usr/share/man/man8/ssh-copy-id.1"

# Install sshd service
clsv -d "$1" sshd.run
